package com.yanqu.road.server.cmd.wingroom.message;

import com.yanqu.road.entity.player.CrossUserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author ：zfr
 * @date ：2022/3/19 23:21
 */
@Cmd(code = CrossProtocol.C_WING_ROOM_GET_MESSAGE_DETAIL_USER_INFO, desc = "获取留言内的玩家信息")
public class CrossGetMessageDetailUserInfoCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        WingRoomProto.GetMessageDetailUserInfoReqMsg reqMsg = WingRoomProto.GetMessageDetailUserInfoReqMsg.parseFrom(packet.getBytes());
        WingRoomProto.GetMessageDetailRespMsg respMsg = reqMsg.getRespMsg();
        CrossUserBaseInfo crossUserBaseInfo = CrossUserMgr.getCrossUserBaseInfo(respMsg.getPlayerId());
        WingRoomProto.GetMessageDetailRespMsg.Builder builder = respMsg.toBuilder();
        if (crossUserBaseInfo != null) {
            builder.setMessagePlayerInfo(PlayerBasePb.parsePlayerBaseTempMsg(crossUserBaseInfo.getUserBaseInfo()));
        }
        YanQuMessage message = YanQuMessageUtils.buildMessage(ClientProtocol.U_WING_ROOM_GET_MESSAGE_DETAIL, builder);
        MessageHelper.sendPacket(reqMsg.getGuestServerId(), reqMsg.getGuestUserId(), message);
    }
}
